package com.hna.eking.AirlineServer.Platform.Common;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hna.eking.AirlineServer.Exception.RunServiceException;
import com.hna.eking.AirlineServer.Mapper.AreaInfo;
import com.hna.eking.AirlineServer.Mapper.CodeInfo;
import com.hna.eking.AirlineServer.Mapper.CountryInfo;
import com.hna.eking.AirlineServer.Platform.Airport.AirportController;
import com.hna.eking.AirlineServer.Service.AreaInfoService;
import com.hna.eking.AirlineServer.Service.CodeInfoService;
import com.hna.eking.AirlineServer.Service.CountryInfoService;
import com.hna.eking.AirlineServer.Utils.ResponseSupport;

@Controller
@RequestMapping(value = "/codeinfo")
public class CodeInfoController {
	Logger logger = LoggerFactory.getLogger(AirportController.class);
	@Autowired
	CountryInfoService counryService;
	@Autowired
	AreaInfoService areaService;
	@Autowired
	CodeInfoService codeService;
	
	/*
	 * 查询所有国家信息
	 * 
	 * 参数： 
	 * 	无 
	 * 
	 * 返回： 
	 * 	国家列表
	 *
	 */
	@RequestMapping(value = "/countrylist", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody ResponseSupport<List<CountryInfo>> getAllCountryCode() {
		ResponseSupport<List<CountryInfo>> rsp = new ResponseSupport<List<CountryInfo>>();
		try {
			/* 查询所有国家信息 */
			List<CountryInfo> ConntryList = counryService.selectAllByCountryCode();
			rsp.setCode(RunServiceException.SUCCESS);
			rsp.setContent(ConntryList);
		}catch (RunServiceException ex) {
			ex.printStackTrace();
			rsp.setCode(ex.getCode());
			rsp.setMessage(ex.getMessage());
			return rsp;
		}
		return rsp;
	}
	/*
	 * 查询地区列表
	 * 
	 * 参数： 
	 * 	无 
	 * 
	 * 返回： 
	 * 	地区列表
	 *
	 */
	@RequestMapping(value = "/arealist", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody ResponseSupport<List<AreaInfo>> getAreayCode(@RequestParam(value = "parentcode", required = false) String parentCode) {
		ResponseSupport<List<AreaInfo>> rsp = new ResponseSupport<List<AreaInfo>>();
		try {
			/* 查询所有国家信息 */
			List<AreaInfo> areaList = areaService.selectAllByParentCode(parentCode);
			rsp.setCode(RunServiceException.SUCCESS);
			rsp.setContent(areaList);
		}catch (RunServiceException ex) {
			ex.printStackTrace();
			rsp.setCode(ex.getCode());
			rsp.setMessage(ex.getMessage());
			return rsp;
		}
		return rsp;
	}
	
	/*
	 * 查询所有的地区列表包含省市县信息
	 * 
	 * 参数： 
	 * 	无 
	 * 
	 * 返回： 
	 * 	地区列表
	 *
	 */
	@RequestMapping(value = "/allarea", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody ResponseSupport<List<AreaInfo>> getAreayCode() {
		ResponseSupport<List<AreaInfo>> rsp = new ResponseSupport<List<AreaInfo>>();
		try {
			/* 查询所有地区信息 */
			List<AreaInfo> areaList = areaService.selectAll();
			rsp.setCode(RunServiceException.SUCCESS);
			rsp.setContent(areaList);
		}catch (RunServiceException ex) {
			ex.printStackTrace();
			rsp.setCode(ex.getCode());
			rsp.setMessage(ex.getMessage());
			return rsp;
		}
		return rsp;
	}
	/*
	 * 查询代码列表
	 * 
	 * 参数： 
	 * 	无 
	 * 
	 * 返回： 
	 * 	代码列表
	 *
	 */
	@RequestMapping(value = "/codelist", method = { RequestMethod.GET, RequestMethod.POST })
	public @ResponseBody ResponseSupport<List<CodeInfo>> getCodeByType(@RequestParam(value = "codetype", required = true) String codeType){
		ResponseSupport<List<CodeInfo>> rsp = new ResponseSupport<List<CodeInfo>>();
		try {
			/* 查询所有代码信息 */
			List<CodeInfo> List = codeService.selectByCodeType(codeType);
			rsp.setCode(RunServiceException.SUCCESS);
			rsp.setContent(List);
		}catch (RunServiceException ex) {
			ex.printStackTrace();
			rsp.setCode(ex.getCode());
			rsp.setMessage(ex.getMessage());
			return rsp;
		}
		return rsp;
	}
}
